package oop;

import java.awt.*;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Locale;

import javax.swing.*;
import javax.swing.border.TitledBorder;
import com.toedter.calendar.JDateChooser;


public class Order extends JPanel{
        /**
         * 
         */
		private static final long serialVersionUID = 1L;
		private Font f;
		private JPanel p1;
		private JPanel p2;
		private JLabel labelHeader,labelSubheader,labelOrderID,labelOrderDate,labelProID,labelProType,labelUnit,
		labelTotal,labelEmpID,labelBath,
		labelNo,labelType,labelBrand,labelModel,labelNum,labelPrice;

		private JTextField textOrderID,textOrderDate,textProID,textProType,textUnit,textTotal,textEmpID;
		private JTextField textNo[],textType[],textBrand[],textModel[],textNum[],textPrice[];
		private JButton buttonFind,buttonClear,buttonAdd,buttonSave;
		private JDateChooser calendar;

        int Width = 569, Height= 440;
                    
        
        public Order(){
                setLayout(null);
                setBorder(BorderFactory.createTitledBorder(null, "Orders", TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION,new Font("Segoe UI",Font.PLAIN,14)));
               
                //setBackground(Color.WHITE);
                setComponent();
                setBounds(10,159, 569, 448);
        }
       
        public void setComponent(){
        		p1 = new JPanel();
        		p1.setBorder(BorderFactory.createTitledBorder(null, "",TitledBorder.LEFT, TitledBorder.DEFAULT_POSITION,new Font("Tahoma",Font.PLAIN,11),Color.GRAY));
        		p1. setLayout(null);
        		add(p1);
        		p1.setBounds(20,70,530,120);
        		p1.setVisible(true);
        		
        		
        		p2 = new JPanel();
        		p2.setBorder(BorderFactory.createTitledBorder(null, "รายการสินค้า",TitledBorder.LEFT, TitledBorder.DEFAULT_POSITION,new Font("Tahoma",Font.PLAIN,11)/*,Color.GRAY*/));
        		p2. setLayout(null);
        		add(p2);
        		p2.setBounds(20,200,530,237);
        		p2.setVisible(true);
        
        		//Create
                labelHeader = new JLabel("ORDER");
        		labelSubheader = new JLabel("แสดงรายละเอียดและแก้ไขข้อมูลใบสั่งซื้อสินค้า..");
        		labelOrderID = new JLabel("รหัสใบสินค้่า:");
        		labelOrderDate = new JLabel("วันซื้อสินค้า:");
        		labelProID = new JLabel("รหัสสินค้่า:");
        		labelProType = new JLabel("ชนิดสินค้่า:");
        		labelEmpID = new JLabel("รหัสพนักงาน:");
        		labelUnit = new JLabel("จำนวน:");
        		labelTotal = new JLabel("ราคารวม:");
        		labelBath = new JLabel("บาท");
        		labelNo = new JLabel("ชิ้นที่");
        		labelType = new JLabel("ประเภท");
        		labelBrand = new JLabel("ยี่ห้อ");
        		labelModel = new JLabel("รุ่น");
        		labelNum = new JLabel("จำนวน");
        		labelPrice = new JLabel("ราคา(บาท)");
        		        		      		
        		textOrderID = new JTextField();
        		textOrderDate = new JTextField();
        		textProID = new JTextField();
        		textProType = new JTextField();
        		textEmpID = new JTextField();
        		textUnit = new JTextField();
        		textTotal = new JTextField();
        		textNo = new JTextField[5];
        		textType = new JTextField[5];
        		textBrand = new JTextField[5];
        		textModel = new JTextField[5];
        		textNum = new JTextField[5];
        		textPrice = new JTextField[5];
        		
        		buttonFind = new JButton("ค้นหา");
        		buttonClear= new JButton("ล้าง");
           		buttonAdd = new JButton("เพิ่ม");
           		buttonSave = new JButton("บันทึก");
         
           		calendar = new JDateChooser();
           		
       		
        		//Add
                add(labelHeader);
                add(labelSubheader);
                p1.add(labelOrderID);
                p1.add(labelOrderDate);
                p1.add(labelProID);
                p1.add(labelProType);
                p1.add(labelUnit);
                p1.add(labelEmpID);
                
                p1.add(textOrderID);
                p1.add(textOrderDate);
                p1.add(textProID);
                p1.add(textProType);
                p1.add(textEmpID);
                p1.add(textUnit);

                p1.add(buttonFind);
                p1.add(buttonClear);
                p1.add(buttonAdd);
                
                p2.add(labelTotal);
                p2.add(labelBath);
                p2.add(textTotal);
                p2.add(labelNo);
                p2.add(labelType);
                p2.add(labelBrand);
                p2.add(labelModel);
                p2.add(labelNum);
                p2.add(labelPrice);
                p2.add(buttonSave);
                
                p1.add(calendar);
                               
              //Set bounds
                labelHeader.setBounds(20, 18, 250, 20);
                labelSubheader.setBounds(20, 40, 250, 20);
                labelOrderID.setBounds(20, 15, 150, 20);
                labelOrderDate.setBounds(220, 15, 100, 20);
                labelProID.setBounds(33, 50, 100, 20);
                labelProType.setBounds(225, 50, 100, 20);
                labelEmpID.setBounds(21, 85, 100, 20);
                labelUnit.setBounds(240, 85, 100, 20);
                labelTotal.setBounds(320, 165, 100, 20);
                labelBath.setBounds(497, 165, 50, 20);
                labelNo.setBounds(22, 20, 40, 25);
                labelType.setBounds(75, 20, 40, 25);
                labelBrand.setBounds(185, 20, 40, 25);
                labelModel.setBounds(312, 20, 40, 25);
                labelNum.setBounds(397, 20, 40, 25); 
                labelPrice.setBounds(448, 20, 60, 25);
                
                textOrderID.setBounds(90, 17, 120, 20);
                textProID.setBounds(90, 52, 120, 20);
                textProType.setBounds(285, 52, 120, 20);
                textEmpID.setBounds(90, 85, 120, 20);
                textUnit.setBounds(285, 85, 120, 20);
                textTotal.setBounds(371, 165, 120,20);

                buttonFind.setBounds(430, 15, 85, 24);
                buttonAdd.setBounds(430, 45, 85, 24);
                buttonClear.setBounds(430, 75, 85, 24);
                buttonSave.setBounds(430, 200, 85, 24);
                
                calendar.setBounds(285, 17, 120, 20);
                calendar.setLocale(new Locale("th", "TH"));
                
                // icon
                buttonFind.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                buttonFind.setIcon(new ImageIcon("D:\\Project\\src\\pic\\search.png"));
                
                buttonAdd.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                buttonAdd.setIcon(new ImageIcon("D:\\Project\\src\\pic\\add.png"));
                
                buttonClear.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                buttonClear.setIcon(new ImageIcon("D:\\Project\\src\\pic\\clear.png"));
                
                buttonSave.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                buttonSave.setIcon(new ImageIcon("D:\\Project\\src\\pic\\save.png"));
                
               //Table
                for(int i=0;i<5;i++){
                	textNo[i] = new JTextField();
        			textType[i] = new JTextField();
        			textBrand[i] = new JTextField();
        			textModel[i] = new JTextField();
        			textNum[i] = new JTextField();
        			textPrice[i] = new JTextField();
        			
        			textNum[i].setForeground(Color.GREEN);
        			textPrice[i].setForeground(Color.GREEN);
        			
        			p2.add(textNo[i]);
        			p2.add(textType[i]);
        			p2.add(textBrand[i]);
        			p2.add(textModel[i]);
        			p2.add(textNum[i]);
        			p2.add(textPrice[i]);
        			
        			
        			textNo[i].setBounds(22, 49+(i*19), 25, 20);
        			textType[i].setBounds(46, 49+(i*19), 100, 20);
        			textBrand[i].setBounds(145, 49+(i*19), 105, 20);
        			textModel[i].setBounds(249, 49+(i*19), 135, 20);
        			textNum[i].setBounds(383, 49+(i*19), 60, 20);
        			textPrice[i].setBounds(442, 49+(i*19), 67, 20);
        			
        			textNo[i].setEditable(false);
        			textType[i].setEditable(false);
        			textBrand[i].setEditable(false);
        			textModel[i].setEditable(false);
        			textNum[i].setEditable(false);
        			textPrice[i].setEditable(false);
        			
        			textNo[i].setBackground(Color.WHITE);
        			textType[i].setBackground(Color.WHITE);
        			textBrand[i].setBackground(Color.WHITE);
        			textModel[i].setBackground(Color.WHITE);
        			textNum[i].setBackground(Color.WHITE);
        			textPrice[i].setBackground(Color.WHITE);
                }
                
        		//Set font
                f = new Font("Tahoma",Font.PLAIN,12);
        		labelHeader.setFont(new Font("Segoe UI",Font.BOLD,18));
        		labelSubheader.setFont(new Font("Tahoma",Font.PLAIN,11));
        		labelOrderID.setFont(f);
        		labelOrderDate.setFont(f);
        		labelProID.setFont(f);
        		labelProType.setFont(f);
        		labelEmpID.setFont(f);
        		labelUnit.setFont(f);
        		labelTotal.setFont(f);
        		labelBath.setFont(f);
        		labelNo.setFont(f);
        		labelType.setFont(f);
        		labelBrand.setFont(f);
        		labelModel.setFont(f);
        		labelNum.setFont(f);
        		labelPrice.setFont(f);
        		
        		textOrderID.setFont(f);
        		textProID.setFont(f);
        		textProType.setFont(f);
        		textEmpID.setFont(f);
        		textUnit.setFont(f);
        		textTotal.setFont(f);

        		buttonFind.setFont(f);
        		buttonClear.setFont(f);
        		buttonAdd.setFont(f);
        		buttonSave.setFont(f);
        		calendar.setFont(f);

                buttonFind.addActionListener(new ActionListener() {
                    
                    @Override
                    public void actionPerformed(ActionEvent arg0) {
                            // TODO Auto-generated method stub
                            OrderFind EmpFind = new OrderFind();
                            EmpFind.setVisible(true);
                    		}
                	});
                
                
        }
}
